<?php

class import extends CActiveRecord {
/**
 * The followings are the available columns in table 'import':
 * @var string $jobno
 * @var string $origin
 * @var string $freight_info
 * @var string $ref
 * @var integer $eta
 * @var string $desc
 * @var double $do_id
 * @var string $carrier
 * @var integer $shipping_line_id
 * @var integer $id
 */

/**
 * Returns the static model of the specified AR class.
 * @return CActiveRecord the static model class
 */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'import';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        return array(
        array('jobno','length','max'=>20),
        array('origin','length','max'=>35),
        array('freight_info','length','max'=>50),
        array('origin','length','max'=>50),
        array('desc','length','max'=>255),
        array('eta','type','type'=>'date','dateFormat'=>'dd/MM/yyyy'),
        array('jobno, eta', 'required', 'on'=>'import'),
        array('shipping_line_id, id, cargo_id', 'numerical', 'integerOnly'=>true),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
        return array(
            'origin'=>array(self::HAS_ONE,'enquiry','origin'),
            'cargo'=>array(self::BELONGS_TO,'cargo','cargo_id'),
            'shipping_line'=>array(self::HAS_ONE,'contact','shipping_line_id'),
            'ref_no'=>array(self::HAS_MANY,'import_ref','import_id'),
        );
    }
    public function beforeSave() {
        $_date = explode("/", $this->eta);
        $this->eta = mktime(0,0,0,$_date[1],$_date[0],$_date[2]);
        return parent::beforeSave();
    }
    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
        'jobno'=>'Job No.',
        'freight_info'=>'Freight Info',
        'eta'=>'ETA',
        'desc'=>'Remark',
        'origin'=>'Originated',
        'mref'=>'Master AWB/BL',
        'href'=>'House AWB/BL',
        );
    }
}